/*
* @Author: Administrator
* @Date:   2017-05-15 16:10:38
* @Last Modified by:   Administrator
* @Last Modified time: 2017-05-16 15:38:42
*/
	$(function(){
			var LI_WIDTH = $('.l-li').width();
			var LI_LENGTH = $(".l-li").length;
			// 添加克隆元素

			$('.l-li').eq(0).clone().appendTo($('.l-ul')).parent().width(LI_WIDTH*(LI_LENGTH+1));

			$('.next').on('click',nextPage)
			$('.prev').on('click',prevPage)
			

			var t = setTimeout(function(){
				$('.next').click();
			},2000)

			$('.b-b-d1').hover(function(){
				clearTimeout(t);
			},function(){
				t = setTimeout(function(){
					$('.next').click();
				},2000)
			})
/*
			function changeDot(index){
				//index 当前Math.abs(left/宽度)  
				//尝试在这里判断是否到最后一页，让第一个点显示
 				$('.dot i').removeClass('active').eq(index).addClass("active");
			}*/

			function nextPage(){
				$('.next').off('click');
				clearTimeout(t);
				var left = parseInt($('.l-ul').css('left'));
				// console.log(left);

				if(left <= -LI_LENGTH*LI_WIDTH){
					left = 0;
					$('.l-ul').css('left',left);

				}

				var index = left == -(LI_LENGTH-1)*LI_WIDTH?0:Math.abs(left/LI_WIDTH)+1;
				// changeDot(index)
				$('.l-ul').animate({'left':(left-LI_WIDTH)},function(){
					$('.next').on('click',nextPage);
					t = setTimeout(function(){
						$('.next').click();
					},2000)
				})
			}



			function prevPage(){
				$('.prev').off('click');
				var left = parseInt($('.l-ul').css('left'));
				if(left >= 0){
					left = -LI_LENGTH*LI_WIDTH;
					$('.l-ul').css('left',left);
				}
				// changeDot(Math.abs(left/LI_WIDTH)-1)
				$('.l-ul').animate({"left":left+LI_WIDTH},function(){
					$('.prev').on('click',prevPage);
				})
			}



		})


































